package com.catmiw.stock.tool;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.catmiw.util.dbf.DBFException;
import com.catmiw.util.dbf.DBFReader;

public class DbfTool {
	public static List<Map<String,String>> dbfToMapList(String dbfFile){
		List<Map<String,String>> lm=new ArrayList<Map<String,String>>();
		
		try {
			DBFReader dbfreader = new DBFReader(dbfFile);
			String field[]=new String[dbfreader.getFieldCount()];
			for (int b = 0; b < dbfreader.getFieldCount(); b++) {
				field[b]=dbfreader.getField(b).getName().trim().toUpperCase();
			}

			while( dbfreader.hasNextRecord()) {
				Map<String,String> map=new HashMap<String,String>();
				String aobj[] = dbfreader.nextRecordString();
				for (int b = 0; b < dbfreader.getFieldCount(); b++) {
					map.put(field[b], aobj[b].trim());
				}
				lm.add(map);
			}
		} catch (DBFException e) {
			e.printStackTrace();
		}
		return lm;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		List<Map<String,String>> lm=dbfToMapList("D:\\new_zszq\\T0002\\hq_cache\\base.dbf");
		for (Map<String,String> map:lm){
			if ("20091001".compareTo(map.get("GXRQ"))<0)
			System.out.println(map.get("GPDM")+"\t"+map.get("GXRQ")+"\t"
					+map.get("ZGB")+"\t"+map.get("JLY")+"\t");
		}
	}

}
